#!/usr/bin/env bash

set -e -u -x
source ./tasks/helpers.sh

task_working_dir

# Install into the task's special _persist directory so that these dependencies
# for the tasks/app/core task are still present if core needs to be re-run, but
# not this task.
mkdir -p _persist
cd _persist

node_modules_dir="$WORK_DIR/tasks/app-deps/admin-ui/pnpm/_persist/node_modules"
mkdir -p json

for locale_path in "$SOURCE_DIR"/locale/*.po; do
  locale="${locale_path##*/}"
  locale="${locale%%.*}"
  PATH="$DEV_INSTALL_PREFIX/bin:$DEFAULT_PATH" "$node_modules_dir/.bin/po2json" \
    --format=jed1.x \
    --domain=api-umbrella \
    "$locale_path" \
    "./json/$locale.json"
done

stamp
